﻿@model PagedList.IPagedList<OMS.Models.UserModelView>

@{
    ViewBag.Title = "Filter";
}

<h2>This page is appointed for creating new and managing existing users</h2><br />
@Html.ActionLink("New user", "AddUser")<br />
Number of Found Users @Html.Display(Model.Count().ToString())

<div>
    @using (Html.BeginForm())
    {
    <select name="field">
        <option value="all">All Fields</option>
        <option value="username" selected>User Name</option>
        <option value="firstname">First Name</option>
        <option value="lastname">Last Name</option>
        <option value="role">Role</option>
    </select>
    <select name="condition">
        <option value="equal">Equal</option>
        <option value="notequal">Not Equal</option>
        <option value="starts" selected>Starts with</option>
        <option value="contains">Contains</option>
        <option value="notcontains">Not Contains</option>
    </select>
    @Html.TextBox("pattern")
    <input type="submit" value="Search" />
    }
</div>
    
<table align=center>
    <tr>
        <th>User Name</th>
        <th>First name</th>
        <th>Last Name</th>
        <th>Role</th>
        <th>Email</th>
        <th>Region</th>
        <th>Edit</th>
        <th>Remove</th>
        <th>Duplicate</th>
    </tr>

@foreach (var user in Model)
{
        <tr>
            <td>
                @Html.DisplayFor(i => user.Login)
            </td>
            <td>
                @Html.DisplayFor(i => user.FirstName)
            </td>
            <td>
                @Html.DisplayFor(i => user.LastName)
            </td>
            <td>
                @Html.DisplayFor(i => user.Role)
            </td>
            <td>
                @Html.DisplayFor(i => user.Email)
            </td>
            <td>
                @Html.DisplayFor(i => user.Region)
            </td>
            <td>
                @Html.ActionLink("Edit", "EditUser", new { id = user.Id })
            </td>
            <td>
                @Html.ActionLink("Remove[WIP]", "DeleteUser", new { id = user.Id })
            </td>
            <td>
                @Html.ActionLink("Duplicate[WIP]", "Duplicate", new { id = user.Id })
            </td>
            <td>        
            </td>
        </tr>
}
</table>
<div align=center>
    Page @(Model. PageCount < Model.PageNumber ? 0 : Model.PageNumber)
    of @Model.PageCount
     
    @if (Model.HasPreviousPage)
    {
        @Html.ActionLink("<<", "Filter", new {field = ViewBag.Field, condition = ViewBag.Condition,
            pattern = ViewBag.Pattern, page = 1 })
        @Html.Raw(" ");
        @Html.ActionLink("< Prev", "Filter", new { field = ViewBag.Field, condition = ViewBag.Condition,
            pattern = ViewBag.Pattern, page = Model.PageNumber - 1 })
    }
    else
    {
        @:<<
        @Html.Raw(" ");
        @:< Prev
    }
    @if (Model.HasNextPage)
    {
        @Html.ActionLink("Next >", "Filter", new {field = ViewBag.Field, condition = ViewBag.Condition,
            pattern = ViewBag.Pattern, page = Model.PageNumber + 1 })
        @Html.Raw(" ");
        @Html.ActionLink(">>", "Filter", new {field = ViewBag.Field, condition = ViewBag.Condition,
            pattern = ViewBag.Pattern, page = Model.PageCount })
    }
    else
    {
        @:Next >
        @Html.Raw(" ")
        @:>>
    }
</div>